#include<bits/stdc++.h>
#define int long long
#define For(i,a,b) for(int i=a;i<=b;++i)
#define Rof(i,a,b) for(int i=a;i>=b;--i)
#define rep(i,a) for(int i=1;i<=a;++i)
#define print(x) printf("%lld\n",(int)x)
#define prn(x) printf("%lld ",(int)x)
using namespace std;
const int N=2e6+5,Mod=998244353;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){f=(ch=='-'?-f:f);ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return x*f;
}
int n;
char s[N];
char t[N];
int dp[N];
int p=0,q=0;
void dfs(int x){
	if(dp[x]>=n*10) return;
	if(dp[x]>=dp[q]-1) return;
	For(l,1,n){
		int p=x;
		For(r,l,n){
			if(x&(1<<(r-1)))p-=(1<<(r-1));
			else p+=(1<<(r-1));
			if(dp[p]>dp[x]+1){
				dp[p]=dp[x]+1;
				dfs(p);
			}
		}
	}
	For(l,1,n){
		int p=x;
		For(r,l,n){
			if(x&(1<<(r-1)));
			else p+=(1<<(r-1));
			if(dp[p]>dp[x]+1){
				dp[p]=dp[x]+1;
				dfs(p);
			}
		}
	}
	For(l,1,n){
		int p=x;
		For(r,l,n){
			if(x&(1<<(r-1)))p-=(1<<(r-1));
			if(dp[p]>dp[x]+1){
				dp[p]=dp[x]+1;
				dfs(p);
			}
		}
	}
}
signed main(){
	freopen("hard.in","r",stdin);
	freopen("hard.out","w",stdout);
	n=read();
	scanf("%s",s+1);
	scanf("%s",t+1);
		if(n<=18){
		memset(dp,0x3f,sizeof(dp));
		For(i,1,n){
			p+=(s[i]=='1')*(1<<(i-1));
			q+=(t[i]=='1')*(1<<(i-1));
		}
		dp[p]=0;
		dfs(p);
		printf("%lld\n",dp[q]);return 0;
	}
	int t=0;
	For(i,1,n){
		if(t[i]!=t[i-1]&&t[i]=='1') t++; 
	}
	printf("%lld\n",t);
	//~ cout<<fixed<<setprecision(10)<<1.0*clock()/CLOCKS_PER_SEC<<endl;
	return 0;
}
//
